<?php if (!defined('BASEPATH'))  exit('No direct script access allowed');
/**
 * @filesource position_grid_form.php
 */
if(0){?><script><?php }?>

Ext.define('Hydcrm.position.PositionGridForm', {
    extend: 'Ext.form.Panel',
    
    requires: [
        'Ext.grid.*',
        'Ext.form.*',
        'Ext.layout.container.Column'
    ],
    xtype: 'form-grid',
    id: 'position_tab',
    frame: true,
    closable: true,
    autoScroll: true,
    bodyPadding: 5,
    layout: 'column',

    buttons: [{
        text: '保存',
        iconCls: 'icon-save',
        handler: function() {
            var store = positionModuleGrid.getStore();
            var count = store.getCount();
            var resourceJson = new Array();    
            for(var i = 0; i< count; i++){ 
                resourceJson[i] = store.getAt(i).data; 
            }
            this.up('form').getForm().submit({
                url: Hydcrm.CONF.CONN_URL,
                params:{
                    module: 'position',
                    action: 'save_position',
                    position_module: Ext.JSON.encode(resourceJson)
                }, 
                method: 'POST',
                waitMsg: '正在更新',
                success: function(form, action) {
                    list_position_ds.load();
                    //Ext.Msg.alert('正确信息', action.result.feedback);
                },
                failure: function(form, action) {
                    Ext.Msg.alert('错误信息', action.result.feedback);
                },
                scope: this
            });
        }
    },{
        text: '新增',
        iconCls: 'icon-add',
        handler: function() {//this.up('form').getForm().submit();
            this.up('form').getForm().reset();
        }
    }],

    initComponent: function(){
        positionModuleGrid = Ext.create('Hydcrm.position.PositionModuleGrid',{positionid:0});
        Ext.apply(this, {
            width: '100%',
            fieldDefaults: {
                labelAlign: 'right',
                labelWidth: 100,
                columnWidth: 0.8,
                margin: 8,
                anchor: '48%',
                msgTarget: 'side'
            },

            items: [{
                columnWidth: 0.35,
                xtype: 'gridpanel',
                id: 'position_gridpanel',
                store: list_position_ds,
                height: '400',
                columns: [{
                    text: '岗位ID',
                    hidden: true,
                    sortable: false,
                    dataIndex: 'id'
                }, {
                    text: '岗位名称',
                    width: 120,
                    sortable: true,
                    dataIndex: 'name'
                }, {
                    text: '岗位描述',
                    flex: 1,
                    sortable: true,
                    dataIndex: 'description'
                }],
                bbar: Ext.create('Ext.PagingToolbar', {
                    store: list_position_ds,
                    displayInfo: true,
                    displayMsg: '显示条目 {0} - {1} of {2}',
                    emptyMsg: "无信息可显示",
                    inputItemWidth: 35,
                    items:[ '-' ]
                }),
                listeners: {
                    scope: this,
                    selectionchange: this.onSelectionChange
                }
            }, {
                columnWidth: 0.65,
                margin: '0 0 0 10',
                xtype: 'fieldset',
                id: 'position_fieldset',
                title:'岗位明细',
                layout: 'column',
                defaultType: 'textfield',
                items: [{
                    fieldLabel: '岗位ID',
                    name: 'id',
                    xtype: 'hidden'
                },{
                    fieldLabel: '岗位名称',
                    name: 'name',
                    allowBlank: false
                },{
                    fieldLabel: '岗位描述',
                    name: 'description',
                    xtype: 'textarea'
                },{xtype: 'fieldset',columnWidth: .99,
                    title: '',
                    id: 'position_module_panel',
                    collapsible: true,
                    collapsed: false,
                    defaults: { //labelWidth: 89,
                        anchor: '100%',
                        layout: {
                            type: 'hbox',
                            defaultMargins: {top: 0, right: 5, bottom: 0, left: 0}
                        }
                    },
                    items: [ positionModuleGrid ]
                } ]
            }]
        });
        this.callParent();
    },
    onSelectionChange: function(model, records) {
        var rec = records[0];
        if (rec) { //alert(rec.get('id'));
            this.getForm().loadRecord(rec);
            Ext.getCmp('position_module_panel').removeAll();
            positionModuleGrid = Ext.create('Hydcrm.position.PositionModuleGrid',{positionid:rec.get('id')});
            Ext.getCmp('position_module_panel').add(positionModuleGrid);
            
        }
    },
    renderStatus: function(val){ //alert(val);
        switch (val) {
            case '0':
                return '解散';
            case '1':
                return '正常';
        }
    }
});

/* End of file position_web_panel.php */
/* Location: ./system/modules/position/views/position_web_panel.php */